package com.example.qwen02;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class WanXiangTestGet {

    public static void main(String[] args) throws Exception {
        // 创建HttpClient实例
        CloseableHttpClient httpClient = HttpClients.createDefault();

        // 创建HttpPost对象，指定URL
        String url = "https://dashscope.aliyuncs.com/api/v1/tasks/a2aa71ac-baab-4013-aad1-0b18bc909af6";
//        HttpPost httpPost = new HttpPost(url);
        HttpGet httpGet = new HttpGet(url);

        // 设置请求头，包括Content-Type为application/json
        httpGet.setHeader("Authorization", "Bearer"+System.getenv("DASHSCOPE_API_KEY"));



        // JSON参数
        String jsonParam = "{\n" +
                "    \"model\": \"wanx-style-repaint-v1\",\n" +
                "    \"input\": {\n" +
                "        \"image_url\": \"https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/public/dashscope/test.png\",\n" +
                "        \"style_index\": 3\n" +
                "    }\n" +
                "}";


        try {
            // 执行HTTP POST请求
            CloseableHttpResponse response = httpClient.execute(httpGet);

            try {
                // 获取响应状态码
                int statusCode = response.getStatusLine().getStatusCode();
                System.out.println("Status Code: " + statusCode);

                // 如果请求成功，读取响应实体
                if (statusCode == 200) {
                    HttpEntity entity = response.getEntity();
                    if (entity != null) {
                        String result = EntityUtils.toString(entity);
                        System.out.println("Response: " + result);
                    }
                } else {
                    System.out.println("Request failed with status code: " + statusCode);
                }

            } finally {
                response.close();
            }

        } finally {
            httpClient.close();
        }
    }

}
